//
//  VideoViewController.m
//  News
//
//  Created by xalo on 16/2/25.
//  Copyright © 2016年 News. All rights reserved.
//

#import "VideoViewController.h"
#import "XMHView.h"

#import "Video_videoController.h"
#import "Video_highlightsController.h"
#import "Video_scencController.h"
#import "Video_funnyController.h"

@interface VideoViewController ()<UIScrollViewDelegate,UITabBarControllerDelegate>

@property (strong, nonatomic) IBOutlet UIScrollView *videoScrollView;

@property (strong, nonatomic) IBOutlet UISegmentedControl *videoSegment;


@property (nonatomic,strong) XMHView *xmview;

@property (nonatomic,assign) BOOL isSelected;













@end

@implementation VideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.isSelected = NO;
    
    self.tabBarController.delegate = self;
    
    
    self.videoScrollView.delegate = self;
    
    [self setVideoSegment];
    
    [self.videoSegment addTarget:self action:@selector(videoSegmentValueChange:) forControlEvents:(UIControlEventValueChanged)];
    
    
    
       // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)setVideoSegment
{

    
    CGFloat width = self.view.frame.size.width;
    self.videoSegment.frame = CGRectMake(width/6, 20, (2*width)/3, 44);

    
    self.videoSegment.tintColor = [UIColor clearColor];

    
    NSDictionary *dict = @{NSForegroundColorAttributeName:[UIColor blackColor]};
    [self.videoSegment setTitleTextAttributes:dict forState:(UIControlStateNormal)];
    NSDictionary *dict2 = @{NSForegroundColorAttributeName:[UIColor redColor]};
    [self.videoSegment setTitleTextAttributes:dict2 forState:(UIControlStateSelected)];
    
    [self.videoSegment setTitleTextAttributes:dict2 forState:(UIControlStateHighlighted)];
    
    
    [self.videoSegment setBackgroundImage:[UIImage imageNamed:@"underline_selected"] forState:(UIControlStateSelected) barMetrics:(UIBarMetricsDefault)];
    [self.videoSegment setBackgroundImage:[UIImage imageNamed:@"underline_selected"] forState:(UIControlStateHighlighted) barMetrics:(UIBarMetricsDefault)];
    [self.videoSegment setBackgroundImage:[UIImage imageNamed:@"underline_Unselected"] forState:(UIControlStateNormal) barMetrics:(UIBarMetricsDefault)];



}



-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat width = scrollView.frame.size.width;
    NSInteger number = self.videoScrollView.contentOffset.x/width;
    
    self.videoSegment.selectedSegmentIndex = number;
    
    
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{

    [[NSNotificationCenter defaultCenter] postNotificationName:@"remove" object:self];

}


-(void)videoSegmentValueChange:(UISegmentedControl *)videoSegment
{
       NSInteger number = [videoSegment selectedSegmentIndex];
    CGFloat width = self.videoScrollView.frame.size.width;
    
    [self.videoScrollView setContentOffset:CGPointMake(number * width, 0) animated:YES];
   
    [[NSNotificationCenter defaultCenter] postNotificationName:@"remove" object:self];
    
  
    
    

}


-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    
   
    
    if (viewController == tabBarController.selectedViewController) {
        
        NSLog(@"beixuanzhong ");
        
    }
    
    
}




@end
